<template>
	<el-dialog title="任务完成情况" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="事件标题" prop="title">
				<el-input v-model="form.title" placeholder="事件标题" clearable></el-input>
			</el-form-item>
			<el-form-item label="完成时间" prop="finishTime">
				<el-date-picker v-model="form.finishTime" placeholder="完成时间" type="date" value-format="YYYY-MM-DD" :disabled-date="publishDateAfter" style="width: 100%;"></el-date-picker>
			</el-form-item>
			<el-form-item label="完成进度" prop="progress">
				<el-input-number v-model="form.progress" placeholder="完成进度" clearable :precision="2" :step="0.1" :max="1" ></el-input-number>
			</el-form-item>
			<el-form-item label="处理结果" prop="remark">
				<el-input v-model="form.remark" placeholder="处理结果" clearable type="textarea" maxlength="380"></el-input>
			</el-form-item>
			<el-form-item label="相关附件">
				<sc-upload-file :apiObj="apiObj" v-model="fileList" :data="{module:'project'}" :showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				<attach-menu v-model:attachIds="form.attachId" :roleFlag="4" :preview="true"></attach-menu>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import AttachMenu from "@/views/module/attachMenu";

export default {
	emits: ['success', 'closed'],
	components: {AttachMenu},
	data() {
		return {
			visible: false,
			isSaveing: false,
			userList: [],
			//所需数据选项
			fileList: [],
			apiObj: this.$API.file.attach.uploadFile,
			form: {
				taskId:"",
				title: '',
				finishTime: '',
				progress:0.1,
				remark: '',
				attachId: '',
			},
			rules: {
				title: [
					{required: true, message: '事件标题不能为空', trigger: 'blur'}
				],
				finishTime: [
					{required: true, message: '完成时间不能为空', trigger: 'blur'}
				],
				progress:[
					{required: true, message: '任务进度不能为空', trigger: 'blur'}
				],
			}
		}
	},
	mounted() {
	},
	methods: {
		publishDateAfter(time) {
			return time.getTime() > Date.now()
		},
		//显示
		open() {
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.project.proTaskProcess.createProcess.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.taskId = data.taskId
			this.form.progress = data.progress
		},
		addNewFile(res, file)
		{
			let tArr = this.form.attachId.split(",");
			tArr.push(res.data.attachId);
			this.form.attachId = tArr.join(",");
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
